Searching in Linux

Finding Stuff in Linux :

  • locate
  • whereis
  • which
  • find

locate:

  • this command go through your entire file system and locate every occurence of the word wriiten
    ex:
    00-33-Linux-Tue-Jul-2025.png
  • sometimes the result of locate is overwhelming or not practical
  • also locate command Database doesn't update in current time it takes update once a day

whereis:

  • whereis helps to locate a binary file, this command returns not olny the location of the file /folder, it returns source and man-page if they are avaliable.
    ex:
    00-42-Linux-Tue-Jul-2025.png

which:

  • its more specific only returns the location of the binaries PATH Variable.

  • Note: PATH is an environment variable stores the location of the file/directory.

    ex:
    01-17-Linux-Tue-Jul-2025.png

find: The Best search utility.

  • the find command utility is the best of them all because it contains more detailed search features ex : it can give the permission, the owner, the group and lastley the date of a file while searching for it.

  • find walks through every folder and subfolder starting from the location you tell it (or your current folder if you don’t specify).
    Tips ✨

  • Use . to search from where you are.

  • Use /path/to/folder to search from a specific folder.

  • Use -name to search by file name.

  • Syntaxfind </directory> -type <f/d/l> -name search_thing

  • -type f searching for a file

  • -type d searching for a Directory.

  • type l search for symbolic link

01-19-Linux-Tue-Jul-2025.png

01-36-Linux-Tue-Jul-2025.png

Wildcards searching ex: *.md:
01-39-Linux-Tue-Jul-2025.png

Search by Wildcard used in find and grep.

to understand about wild card with usages in linux we will create empty files ./home/kali/ hat bat cat and what

touch /home/kali/hat /home/kali/bat /home/kali/cat /home/kali/what

──(kali㉿kali)-[~]
└─$ find . -type f -name "[w]hat"
./what
                                                                                                                  
┌──(kali㉿kali)-[~]
└─$ find . -type f -name "[b]at" 
./bat
                                                                                                                  
┌──(kali㉿kali)-[~]
└─$ find . -type f -name "[cb]at"
./bat
./cat
Wildcard Meaning Example Matches
* Any number of characters "*.txt" file.txt, abc.txt
? Exactly one character "b?t" bat, bit
[c,b] One of the listed characters "[cb]at" cat, bat

grep: Searching in the file or piping:

  • grep help us to search in files or config files and can be combined with other commands using piping |.
  • | grep most commonly used in piping because allows grep to grap the output of the previous command then can be used as an input.

Examples of piping with grep :

  • see how the grep filtered the output of the findcommand
    02-43-Linux-Tue-Jul-2025.png
Searching In files using grep example:
  • as u can see the output gave us occurrence of the word linux in my .md file.

03-09-Linux-Tue-Jul-2025.png

grep on an interface in ip a command:

03-19-Linux-Tue-Jul-2025.png